class Solution {
public:
    int eraseOverlapIntervals(vector<vector<int>>& intervals) {
        sort(intervals.begin(), intervals.end());
        int ret = 0;
        int left = intervals[0][0], right = intervals[0][1];
        for(auto& e : intervals)
        {
            if(e[0] >= right) // 不重叠
            {
                left = e[0], right = e[1];
            }
            else // 重叠
            {
                ++ret;
                right = min(right, e[1]); // 保留右端点较小的区间
            }
        }
        return ret - 1; // 从第一个区间开始比较就删掉第一个区间
    }
};